<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="../node_modules/react/umd/react.development.js"></script>
    <script src="../node_modules/react-dom/umd/react-dom.development.js"></script>
    <script src="../node_modules/babel-standalone/babel.min.js"></script>
  </head>
  <body>
    <div id="reactDom"></div>
    <script type="text/babel">
      // react列表渲染  map()
      let arr = ["吃饭", "睡觉", "打豆豆"];
      let index = -1;
      let myDom = arr.map((item, i) => {
        //   key必须是独一无二的
        return (
          <p
            key={i}
            style={{ color: i == index ? "red" : "" }}
            onClick={() => {
              index = i;
              console.log(index + "----" + i);
            }}
          >
            {item}
          </p>
        );
      });

      //   必须使用map循环吗?
      // for in循环
      //   function fun() {
      //     let newarr = [];
      //     for (let index in arr) {
      //       newarr.push(<p>{arr[index]}</p>);
      //     }
      //   }

      ReactDOM.render(myDom, document.getElementById("reactDom"));
    </script>
  </body>
</html>
